﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace ourAdd_in
{
    public partial class ucLogin : UserControl
    {
        AccountBUS bus = new AccountBUS();
        public ucLogin()
        {
            InitializeComponent();
        }

        public delegate void logIn_fireFormLogin();
        public event logIn_fireFormLogin OnLogIn;

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            bool check=bus.CheckPassword(txtEmail.Text.Trim(), txtPassword.Text.Trim());
            if (check == false)
            {
                MessageBox.Show("Password không đúng!");
                txtPassword.Focus();
            }
            else
            {
                if (OnLogIn != null)
                {
                    OnLogIn();
                }
                Form f = this.FindForm();
                f.Close();
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            txtEmail.Clear();
            txtPassword.Clear();
            Form f = this.FindForm();
            f.Close();
            
        }

        private void btnCreateNewAccount_Click(object sender, EventArgs e)
        {
            Form f = new frmRegister();
            f.Show();
            Form f1 = this.FindForm();
            f1.Dispose();
        }

        private void txtEmail_Validated(object sender, EventArgs e)
        {
            bool result = bus.CheckEmail(txtEmail.Text);
            if (result == false && txtEmail.Text.CompareTo("")!=0)
            {
                if ((MessageBox.Show("Không tồn tại Email này! Bạn có muốn tạo mới tài khoản hay không?", "Chú ý", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No))
                    txtEmail.Focus();
                else
                {

                    Form f = new frmRegister();
                    f.Show();
                    Form f1 = this.FindForm();
                    f1.Dispose();
                }
            }
            else
            {
 
            }
        }
    }
}
